# Simple Matrix Class to use for Adjacency Matrix and etc
# Matrix is made up of list of lists
# Index of Columns and Rows start with 1 instead of zero.

class matrix:
	def __init__(self, rows, cols):
		if (type(rows) is not int) or (type(cols) is not int):
			raise TypeError("Both row and col index has to be integers")
		if rows <= 0 or cols <= 0:
			raise IndexError("Rows and Columns must be Positive")
		self.rows = rows
		self.cols = cols
		self.matrix = []
		'''Initialization of the matrix with all zeroes'''
		for i in range(rows):
			i_row = []
			for j in range(cols):
				i_row.append(0)
			self.matrix.append(i_row)

	def getRows(self):
		''' Returns the number of rows of the matrix '''
		return self.rows

	def getCols(self):
		''' Returns the number of cols of the matrix '''
		return self.cols

	def getDim(self):
		''' Returns the dimension of the matrix '''
		return self.rows * self.cols

	def getItem(self, row, col):
		'''Returns the item of the given column and row'''
		if (type(row) is not int) or (type(col) is not int):
			raise TypeError("Indexes must be integers")
		if row > self.rows or row < 1:
			raise ValueError("Row must be within the boundary")
		if col > self.cols or col < 1:
			raise ValueError("Column must be within the boundary")
		return self.matrix[row-1][col-1]

	def setItem(self, row, col, num):
		'''Sets the item of the given column and row'''
		if (type(row) is not int) or (type(col) is not int):
			raise TypeError("Indexes must be integers")
		if row > self.rows or row < 1:
			raise ValueError("Row must be within the boundary")
		if col > self.cols or col < 1:
			raise ValueError("Column must be within the boundary")
		self.matrix[row-1][col-1] = num

	def setAll(self, num):
		'''Sets all the element to be the input'''
		for i in range(self.rows):
			for j in range(self.cols):
				self.matrix[i][j] = num

	def __repr__(self):
		result = ''
		for i in range(self.rows):
			result += '%s\n' % (self.matrix[i])
		return result


# TODO: Other Matrix Operators when needed
